import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/*
    PCB
    进程对象
 */
public class PCB {
    private ProcessState state;
    private final int processID;
    private int progressCount;
    private int base;
    private int offset;
    private PCB nextPCB;
    private PCB prevPCB;
    //父进程
    private PCB fatherProcess;
    //子进程
    private List<PCB> sonProcessList;
    private int pageTableSize;
    //进程打开文件表
    private List<File> openFileList;
    //进程页表
    private List<PageTableUnit> pageTable;

    public int getProcessID() {
        return processID;
    }

    public void setValidBit(int index, boolean valid) {
        if (index >= pageTableSize)
            return;
        pageTable.get(index).setValidBit(valid);

    }

    public void addSonProcess(PCB sonPCB) {
        this.sonProcessList.add(sonPCB);
    }

    public PCB(Process fatherProcess, int processID,int base,int offset) {
        this.sonProcessList=new ArrayList<>();
        this.openFileList=new ArrayList<>();
        this.pageTable=new ArrayList<>();
        this.base=base;
        this.offset=offset;
        this.state=ProcessState.NEW;

        this.fatherProcess = fatherProcess.getPCB();
        fatherProcess.getPCB().addSonProcess(this);
        this.processID = processID;
    }

    public void setNextPCB(PCB nextPCB) {
        this.nextPCB = nextPCB;
    }

    public void setPrevPCB(PCB prevPCB) {
        this.prevPCB = prevPCB;
    }

    public List<PageTableUnit> getPageTable() {
        return pageTable;
    }
}
